package Controller;



import Service.LoginAndRegisterService;
import models.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by 郑凯 on 2016/6/9.
 */
@Controller
public class LoginAndRegisterController {

    @Autowired
    private LoginAndRegisterService loginAndRegisterService;

    @RequestMapping("Login")
    public String login(@RequestParam String name, @RequestParam String password,Model model){

        if(loginAndRegisterService.login(name,password))
        {

            return "redirect:index";
        }

        else
        {
            model.addAttribute("tip","账号或密码错误");
            return "login";
        }
    }
    @RequestMapping("Register")
    public ModelAndView register(@RequestParam String name, @RequestParam String password, @RequestParam String email){
        if(loginAndRegisterService.register(name,password,email)) return new ModelAndView("login","tip","");
        return new ModelAndView("register","tip","该账号已注册");
    }
}
